/*
 * @Author: MarsLay 331412466@qq.com
 * @Date: 2022-11-04 11:44:31
 * @LastEditors: MarsLay 331412466@qq.com
 * @LastEditTime: 2022-11-04 11:45:46
 * @FilePath: \smart-sports-manage\utils\loading.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
let needLoadingRequestCount = 0;
let loadingTimer;
export function showLoading(title = '', mask = true) {
    if (needLoadingRequestCount === 0) {
        uni.showLoading({
            title,
            mask
        });

        // 最长10s自动关闭
        loadingTimer = setTimeout(() => {
            if (needLoadingRequestCount > 0) {
                uni.hideLoading();
            }
        }, 10000);
    }

    needLoadingRequestCount++;
}

// 隐藏遮罩
export function hideLoading() {
    if (needLoadingRequestCount <= 0) return;

    needLoadingRequestCount--;

    if (needLoadingRequestCount === 0) {
        loadingTimer && clearTimeout(loadingTimer);
        uni.hideLoading();
    }
}